package com.ysx.server.service.impl;

import com.ysx.server.mapper.GoodsMapper;
import com.ysx.server.mapper.MessageParentMapper;
import com.ysx.server.pojo.entity.Goods;
import com.ysx.server.pojo.entity.MessageParent;
import com.ysx.server.service.GoodsService;
import com.ysx.server.service.MessageParentService;
import lombok.extern.slf4j.Slf4j;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class MessageParentServiceImpl implements MessageParentService {

    @Autowired
    private GoodsMapper goodsMapper;

    @Autowired
    private MessageParentMapper messageParentMapper;

    /**
     * 保存留言父本
     *
     * @param sendName
     * @param goodsId
     */
    @Override
    public void save(String sendName, Long goodsId) {
        Goods goods = goodsMapper.getById(goodsId);
        MessageParent messageParent = new MessageParent();
        messageParent.setGoodsId(goodsId);
        messageParent.setGoodsName(goods.getGoodsName());
        messageParent.setCreateName(sendName);
        messageParent.setMsgStatus(1);
        messageParentMapper.save(messageParent);
    }

    /**
     * 修改留言状态
     *
     * @param parentId
     */
    @Override
    public void updateStatus(Long parentId) {
        messageParentMapper.updateStatusOK(parentId);
    }
}
